<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>站心坐标转换</title>
    <link href="../Build/Cesium/Widgets/widgets.css" rel="stylesheet" />
    <script src="../Build/Cesium/Cesium.js"></script>
    <script src="plugin/ecefLlhEnu.js"></script>
    <style>
        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>

</head>

<body>
    <div id="cesiumContainer"></div>
    <script>
        let osm = Cesium.createOpenStreetMapImageryProvider({
            url: 'https://a.tile.openstreetmap.org/'
        });
        let viewer = new Cesium.Viewer('cesiumContainer', {
            imageryProvider: osm,
            contextOptions: {
                webgl: {
                    alpha: true
                }
            },
            selectionIndicator: false,
            animation: false,  //是否显示动画控件
            baseLayerPicker: false, //是否显示图层选择控件
            geocoder: false, //是否显示地名查找控件
            timeline: false, //是否显示时间线控件
            sceneModePicker: false, //是否显示投影方式控件
            navigationHelpButton: false, //是否显示帮助信息控件
            infoBox: false,  //是否显示点击要素之后显示的信息
            fullscreenButton: false
        });
        //取消双击事件
        viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
        //设置homebutton的位置
        Cesium.Camera.DEFAULT_VIEW_RECTANGLE =
            Cesium.Rectangle.fromDegrees(110.15, 34.54, 110.25, 34.56);//Rectangle(west, south, east, north)
        //设置初始位置
        viewer.camera.setView({
            destination: Cesium.Cartesian3.fromDegrees(110.20, 34.55, 3000000)
        });

        //开启深度检测
        viewer.scene.globe.depthTestAgainstTerrain = true;

        //点
        viewer.entities.add({
            name: '点',
            position: Cesium.Cartesian3.fromDegrees(104, 30, 0),
            point: {
                pixelSize: 10,
                color: Cesium.Color.YELLOW
            }
        });


        let tool = new mathTool();
        let enpoint = tool.enu_to_ecef({ longitude: 104, latitude: 30, altitude: 0 }, { distance: 800, azimuth: 45, elevation: 30 });
        let espoint = tool.enu_to_ecef({ longitude: 104, latitude: 30, altitude: 0 }, { distance: 800, azimuth: 45, elevation: 60 });
        let wspoint = tool.enu_to_ecef({ longitude: 104, latitude: 30, altitude: 0 }, { distance: 800, azimuth: 225, elevation: 30 });
        let wnpoint = tool.enu_to_ecef({ longitude: 104, latitude: 30, altitude: 0 }, { distance: 800, azimuth: 225, elevation: 60 });

        viewer.entities.add({
            name: '点',
            position: Cesium.Cartesian3.fromDegrees(enpoint.longitude, enpoint.latitude, enpoint.altitude),
            point: {
                pixelSize: 10,
                color: Cesium.Color.BLUE
            }
        });
        viewer.entities.add({
            name: '橙色线',
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArrayHeights([104, 30, 0,
                enpoint.longitude, enpoint.latitude, enpoint.altitude]),
                width: 5,
                material: new Cesium.PolylineOutlineMaterialProperty({
                    color: Cesium.Color.ORANGE,
                    outlineWidth: 2,
                    outlineColor: Cesium.Color.BLACK
                })
            }
        });

        viewer.entities.add({
            name: '点',
            position: Cesium.Cartesian3.fromDegrees(espoint.longitude, espoint.latitude, espoint.altitude),
            point: {
                pixelSize: 10,
                color: Cesium.Color.BLUE
            }
        });
        viewer.entities.add({
            name: '橙色线',
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArrayHeights([104, 30, 0,
                espoint.longitude, espoint.latitude, espoint.altitude]),
                width: 5,
                material: new Cesium.PolylineOutlineMaterialProperty({
                    color: Cesium.Color.ORANGE,
                    outlineWidth: 2,
                    outlineColor: Cesium.Color.BLACK
                })
            }
        });

        viewer.entities.add({
            name: '点',
            position: Cesium.Cartesian3.fromDegrees(wspoint.longitude, wspoint.latitude, wspoint.altitude),
            point: {
                pixelSize: 10,
                color: Cesium.Color.BLUE
            }
        });
        viewer.entities.add({
            name: '橙色线',
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArrayHeights([104, 30, 0,
                wspoint.longitude, wspoint.latitude, wspoint.altitude]),
                width: 5,
                material: new Cesium.PolylineOutlineMaterialProperty({
                    color: Cesium.Color.ORANGE,
                    outlineWidth: 2,
                    outlineColor: Cesium.Color.BLACK
                })
            }
        });

        viewer.entities.add({
            name: '点',
            position: Cesium.Cartesian3.fromDegrees(wnpoint.longitude, wnpoint.latitude, wnpoint.altitude),
            point: {
                pixelSize: 10,
                color: Cesium.Color.BLUE
            }
        });
        viewer.entities.add({
            name: '橙色线',
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArrayHeights([104, 30, 0,
                wnpoint.longitude, wnpoint.latitude, wnpoint.altitude]),
                width: 5,
                material: new Cesium.PolylineOutlineMaterialProperty({
                    color: Cesium.Color.ORANGE,
                    outlineWidth: 2,
                    outlineColor: Cesium.Color.BLACK
                })
            }
        });

    </script>
</body>

</html>